<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>家庭表</title>

</head>
<body class="easyui-layout" data-options="fit:true"
	style="font-family: '微软雅黑'">
	<div
		data-options="region:'north',split:true,border:false,title:'家庭户主列表'"
		style="width: auto">
		<div id="tb" style="padding: 5px; height: auto">
			<form id="searchFrom" action="">
				<input type="text" name="filter_LIKES_housemaster"
					class="easyui-validatebox" data-options="width:150,prompt: '户主姓名'" />
				<span class="toolbar-item dialog-tool-separator"></span> <a
					href="javascript(0)" class="easyui-linkbutton" plain="true"
					iconCls="icon-search" onclick="cx()">查询</a>
			</form>
		</div>
		<table id="dg"></table>
	</div>
	<div
		data-options="region:'center',split:true,border:false,title:'家庭成员列表'"
		style="width: auto">
		<table id="familyInfoDg"></table>
	</div>
	<div
		data-options="region:'south',border:true,collapsible:false,title:'参合登记列表'"
		style="height: auto">
		<div id="partInstTb" style="height: auto">
			<div>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-remove" plain="true" data-options="disabled:false"
					onclick="infoDel()">删除</a> <span
					class="toolbar-item dialog-tool-separator"></span> <a
					href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-edit" plain="true" onclick="infoUpd()">修改</a> <span
					class="toolbar-item dialog-tool-separator"></span>
			</div>
		</div>
		<table id="partInstDg"></table>
	</div>
	<div id="dlg"></div>
	<script type="text/javascript">
		var dg;
		var familyInfoDg;
		var partInstDg;
		var d;
		$(function() {
			dg = $('#dg').datagrid(
					{
						url : '${path}/family/dataGrid',
						striped : true,
						rownumbers : true,
						pagination : true,
						singleSelect : true,
						idField : 'id',
						sortName : 'id',
						sortOrder : 'asc',
						pageSize : 20,
						pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400,
								500 ],
						frozenColumns : [ [ {
							width : '100',
							title : '编号',
							field : 'id',
							sortable : true
						}, {
							width : '150',
							title : '家庭编号',
							field : 'familyNo',
							sortable : true
						}, {
							width : '100',
							title : '户主名称',
							field : 'housemaster',
							sortable : true
						}, {
							width : '150',
							title : '身份证号',
							field : 'cardNo',
							sortable : true
						},

						{
							width : '150',
							title : '所在村编号',
							field : 'areaNo',
							sortable : true
						}, {
							width : '200',
							title : '建档时间',
							field : 'createDate',
							sortable : true
						}

						] ],
						headerContextMenu : [
								{
									text : "冻结该列",
									disabled : function(e, field) {
										return dg.datagrid("getColumnFields",
												true).contains(field);
									},
									handler : function(e, field) {
										dg.datagrid("freezeColumn", field);
									}
								},
								{
									text : "取消冻结该列",
									disabled : function(e, field) {
										return dg.datagrid("getColumnFields",
												false).contains(field);
									},
									handler : function(e, field) {
										dg.datagrid("unfreezeColumn", field);
									}
								} ],
						enableHeaderClickMenu : true,
						enableHeaderContextMenu : true,
						enableRowContextMenu : false,
						toolbar : '#tb',
						onClickRow : function(rowIndex, rowData) {
							var familyNo = rowData.familyNo;
							familyInfoDg = $('#familyInfoDg');
							partInstDg = $('#partInstDg');
							familyInfoDg.datagrid({
								url : '${path}/familyInfo/dataGrid?familyNo='
										+ familyNo
							});
							familyInfoDg.datagrid('reload', {
								filter_EQS_familyNo : familyNo
							})
							partInstDg.datagrid({
								url : '${path}/partInst/dataGrid?familyNo='
										+ familyNo
							});
							partInstDg.datagrid('reload', {
								filter_EQS_familyNo : familyNo
							})
						}
					});
		});

		//创建查询对象并查询
		function cx() {
			var obj = $("#searchFrom").serializeObject();
			dg.datagrid('load', obj);
		}
		//时间格式化
		function dateFormatter(value) {
			var date = new Date(value);
			return dateFtt('yyyy-MM-dd hh:mm:ss', date);
		}

		$(function() {
			familyInfoDg = $('#familyInfoDg').datagrid(
					{

						// url : '${path}/familyInfo/dataGrid',
						striped : true,
						rownumbers : true,
						pagination : true,
						singleSelect : true,
						idField : 'id',
						sortName : 'id',
						sortOrder : 'asc',
						pageSize : 20,
						pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400,
								500 ],
						columns : [ [ {
							width : '50',
							title : '编号',
							field : 'id',
							sortable : true
						}, {
							width : '80',
							title : 'familyInfoNo',
							field : 'familyInfoNo',
							sortable : true
						}, {
							width : '150',
							title : '家庭编号',
							field : 'familyNo',
							sortable : true
						}, {
							width : '150',
							title : '身份证号',
							field : 'cardNo',
							sortable : true
						},

						{
							width : '100',
							title : '与户主关系',
							field : 'relaType',
							sortable : true
						}, {
							width : '100',
							title : '是否参合',
							field : 'partState',
							sortable : true
						},
						{
							width : '100',
							title : '是否参合',
							field : 'createDate',
							formatter : partOper
						},] ],
						headerContextMenu : [
								{
									text : "冻结该列",
									disabled : function(e, field) {
										return familyInfoDg.datagrid(
												"getColumnFields", true)
												.contains(field);
									},
									handler : function(e, field) {
										familyInfoDg.datagrid("freezeColumn",
												field);
									}
								},
								{
									text : "取消冻结该列",
									disabled : function(e, field) {
										return familyInfoDg.datagrid(
												"getColumnFields", false)
												.contains(field);
									},
									handler : function(e, field) {
										familyInfoDg.datagrid("unfreezeColumn",
												field);
									}
								} ],
						enableHeaderClickMenu : true,
						enableHeaderContextMenu : true,
						enableRowContextMenu : false,
						toolbar : '#familyInfoTb'
					});
		});

		$(function() {
			partInstDg = $('#partInstDg').datagrid(
					{

						 
						striped : true,
						rownumbers : true,
						pagination : true,
						singleSelect : true,
						idField : 'partNo',
						sortName : 'partNo',
						sortOrder : 'asc',
						pageSize : 20,
						pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400,
								500 ],
						columns : [ [ {
							width : '50',
							title : '编号',
							field : 'id',
							sortable : true
						},  {
							width : '150',
							title : '家庭编号',
							field : 'partNo',
							sortable : true
						}, {
							width : '150',
							title : '家庭编号',
							field : 'familyNo',
							sortable : true
						},{
							width : '150',
							title : '家庭成员编号',
							field : 'familyInfoNo',
							sortable : true
						},
						{
							width : '100',
							title : '姓名',
							field : 'name',
							sortable : true
						}, {
							width : '100',
							title : '性别',
							field : 'gender',
							sortable : true
						}, {
							width : '100',
							title : '年齡',
							field : 'age',
							sortable : true
						}, {
							width : '100',
							title : '联系方式',
							field : 'contact',
							sortable : true
						}, {
							width : '100',
							title : '家庭住址',
							field : 'address',
							sortable : true
						}, {
							width : '100',
							title : '参合时间',
							field : 'partTime',
							sortable : true
						}, {
							width : '100',
							title : '发票号',
							field : 'invoNo',
							sortable : true
						},
						{
							field : 'action',
							title : '操作',
							width : 200,
							formatter : function(value, row, index) {
								var str = '';
								<shiro:hasPermission name="/partInfo/edit">
								str += $
										.formatString(
												'<a href="javascript:void(0)" class="partInfo-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="partInfoEditFun(\'{0}\');" >编辑</a>',
												row.id);
								</shiro:hasPermission>
								<shiro:hasPermission name="/partInfo/delete">
								str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
								str += $
										.formatString(
												'<a href="javascript:void(0)" class="partInfo-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="partInfoDeleteFun(\'{0}\');" >删除</a>',
												row.partNo);
								</shiro:hasPermission>
								return str;
							}
						} ] ],
						headerContextMenu : [
								{
									text : "冻结该列",
									disabled : function(e, field) {
										return partInstDg.datagrid(
												"getColumnFields", true)
												.contains(field);
									},
									handler : function(e, field) {
										partInstDg.datagrid("freezeColumn",
												field);
									}
								},
								{
									text : "取消冻结该列",
									disabled : function(e, field) {
										return partInstDg.datagrid(
												"getColumnFields", false)
												.contains(field);
									},
									handler : function(e, field) {
										partInstDg.datagrid("unfreezeColumn",
												field);
									}
								} ],
						enableHeaderClickMenu : true,
						enableHeaderContextMenu : true,
						enableRowContextMenu : false,
						toolbar : '#partInstTb'
					});
		});


 
 /**
	 * 删除
	 */
	function partInfoDeleteFun(partNo) {
		alert(partNo);
		parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
			if (b) {
				progressLoad();
				$.post('${path}/partInst/delete', {
					partNo : partNo
				}, function(result) {
					if (result.success) {
						parent.$.messager.alert('提示', result.msg, 'info');
						//familyDataGrid.datagrid('reload');
					}
					progressClose();
				}, 'JSON');
			}
		});
	}
 
		//弹窗修改
		function infoUpd() {
			var row = partInstDg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '修改',
				width : 380,
				height : 340,
				//    href:'${ctx}/exp/partInst/update/'+row.partNo,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '修改',
					handler : function() {
						$('#mainform').submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}

		//查看
		function infoLook() {
			var row = familyInfoDg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '查看',
				width : 380,
				height : 340,
				//   href:'${ctx}/exp/partInst/'+row.partNo,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}
		//参合登记
		function partOper(val,row,index){  
			if(row.partState=='未参合'){
				 return '<a href="#" onclick="partAdd('+row.id+')">参合登记</a>';  
			}else{
				return '';
			}
		} 

		//参合登记頁面
		function partAdd(id) {
			d=$("#dlg").dialog({   
			    title: '参合登记',    
			    width: 700,    
			    height: 700,
			    type:'get',
			    href:'${path}/partInst/addPageOK?id='+id,
			    maximizable:true,
			    modal:true,
			    buttons:[{
					text:'确认',
					handler:function(){
						$("#partInstEditForm").submit(); 
						//partInstDg.datagrid('reload');
						//familyInfoDg.datagrid('reload');
					}
				}]
			});
		}
	</script>
</body>
</html>